package tests;

import static org.junit.Assert.*;
import il.ac.technion.wiki.api.Author;
import il.ac.technion.wiki.api.Content;
import il.ac.technion.wiki.api.Metadata;
import il.ac.technion.wiki.api.Metadata.Language;
import il.ac.technion.wiki.api.WikiPageExceptions;
import il.ac.technion.wiki.impl.HtmlContent;

import java.util.Date;

import org.junit.Test;

import wiki.base.WikiPageDI;

public class TestDIWiki {
	@Test
	public void testWikiPageDI() throws WikiPageExceptions {
		DbStub db = new DbStub();
		WikiPageDI wiki = new WikiPageDI(db);
		
		Metadata meta = new Metadata("foo", new Date(), Language.ENGLISH, new Author("s", "a", "k"));
		HtmlContent c = new HtmlContent(meta, "<a href='google.com'>hi</a> <i>there</i>");
		wiki.addNewPage(c);
		
		assertEquals("add", db.lastMethods.pop());
		assertEquals("DbStub()", db.lastMethods.pop());
		
		Content found = wiki.getCurrentVersion("foo");
		assertEquals("hi there", found.getPlainText());
		
		assertEquals("isExists", db.lastMethods.pop());
		assertEquals("getCurrentVersion", db.lastMethods.pop());
	}
}
